<template lang="pug">
  .tab-1
    Table.hasTitle-table.beautiful-table(:columns="thead" :data="bargainList")
      //- .pr-24.pl-24(slot="header")
      //-   .pull-right
      //-     Button.mr-15(type="info" size="small" @click="addContact") 添加联系人
      template(slot-scope="{ row, index }" slot="brief")
        //- .u-d-info {{row.brief}}
        span {{row.brief}}
      template(slot-scope="{ row, index }" slot="action")
        Button.mr-10(type="text" size="small" @click="reviseBtn(row)") 修改
        //- Button(type="text" size="small") 删除
    Modal(v-model="reviseModal" title="合作")
      Form(ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="130")
        FormItem.mb-5(label="所属需求：")
          //- Input(v-model="formValidate.brief" placeholder="请输入" disabled)
          div {{formValidate.brief}}
        FormItem.mb-5(label="合作名称：" prop="name")
          Input(v-model="formValidate.name" placeholder="请输入")
        FormItem.mb-5(label="合作金额：" prop="price")
          Input(v-model="formValidate.price" placeholder="请输入")
        FormItem.mb-5(label="合作内容：" prop="content")
          Input(v-model="formValidate.content" placeholder="请输入")
        FormItem.mb-5(label="谈判挑战：" prop="challenge")
          Input(v-model="formValidate.challenge" placeholder="请输入")
        FormItem.mb-5(label="谈判策略：" prop="strategy")
          Input(v-model="formValidate.strategy" placeholder="请输入")
        FormItem.mb-5(label="备注信息：")
          Input(v-model="formValidate.remark" type="textarea" placeholder="请输入")
      template(slot="footer")
        Button(type="info" @click="handleSubmit('formValidate')") 提交
        Button(@click="reviseModal = false") 取消
</template>

<script>
import HRDCCustomerApi from '@/api/HRDCCustomer.api.js'

export default {
  props: {
    bargainList: Array
  },
  data () {
    return {
      isCheck: true,
      name: '总经理',
      reviseModal: false,
      thead: [
        {
          title: '新增时间',
          minWidth: 150,
          render: (h, params) => {
            let row = params.row
            let times = ''
            if (row.createTime) {
              times = row.createTime.slice(0, 19).replace(/T/g, ' ')
            }
            return h('span', times)
          }
        },
        {
          title: '需求编号',
          minWidth: 100,
          key: 'requirementCode'
        },
        {
          title: '客户需求',
          minWidth: 100,
          slot: 'brief'
        },
        {
          title: '合作名称',
          minWidth: 100,
          key: 'name'
        },
        {
          title: '合作金额',
          minWidth: 100,
          key: 'price'
        },
        {
          title: '合作内容',
          minWidth: 100,
          key: 'content'
        },
        {
          title: '谈判策略',
          minWidth: 100,
          key: 'strategy'
        },
        {
          title: '备注信息',
          minWidth: 100,
          key: 'remark'
        },
        {
          title: '记录销售',
          minWidth: 100,
          key: 'createrName'
        },
        {
          title: '操作',
          minWidth: 140,
          slot: 'action'
        }
      ],
      formValidate: {},
      ruleValidate: {
        name: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        price: [
          { required: true, message: '价格不能为空', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '内容不能为空', trigger: 'blur' }
        ],
        challenge: [
          { required: true, message: '挑战不能为空', trigger: 'blur' }
        ],
        strategy: [
          { required: true, message: '策略不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    reviseBtn (obj) {
      this.formValidate = obj
      this.reviseModal = true
    },
    handleSubmit (name) {
      HRDCCustomerApi.PostBargain(this.formValidate).then(res => {
        if (res.data.success) {
          this.$Message.success(res.data.message)
          this.reviseModal = false
          this.$emit('get-list')
        } else {
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    }
  }
}
</script>

<style>

</style>
